﻿using System;
using System.Collections.Generic;
using System.Text;

using SharpDX.RawInput;

namespace SpaceBattle
{
    public delegate void KeyboardEventHandler(object sender, KeyboardInputEventArgs args);

    class KeyboardInput
    {
        private List<System.Windows.Forms.Keys> Keys = new List<System.Windows.Forms.Keys>();
        private int MaxBufferSize = 256;

        public System.Windows.Forms.Keys GetLastKey()
        {
            if (Keys.Count > 0)
            {
                return Keys[Keys.Count - 1];
            }
            return System.Windows.Forms.Keys.None;
        }

        public KeyboardInput()
        {
        }

        public event KeyboardEventHandler KeyPressed;

        public void Update(object sender, KeyboardInputEventArgs args)
        {
            if (Keys.Count > MaxBufferSize)
            {
                Keys.RemoveAt(0);
            }
            Keys.Add(args.Key);

            if (KeyPressed != null)            
                KeyPressed(sender, args);                        
        }
    }
}
